﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ExamSharedClasses
{   
    /// <summary>
    /// (k) Die Basisklasse Answer beinhaltet einige gemeinsame Elemente, die
    /// an die spezielleren vererbt werden.
    /// -Bezug ExamId, AnswerId, UserId
    /// -Bewertung
    /// -Bezug auf Frage
    /// </summary>
    [Serializable()]
    public class Answer 
    {
        public const String TABLENAME = "answer";
        public const String ANSWER_EXAM_ID = "answer_exam_id";
        public const String ANSWER_QUESTION_ID = "answer_question_id";
        public const String ANSWER_USER_ID = "answer_user_id";
        public const String ANSWER_NUMBER = "answer_number";
        public const String ANSWER_RATING = "answer_rating";

        public int AnswerExamId { get; set; }   // ex Exam
        public Question AnswerQuestion { get; set; }
        public int AnswerUserId { get; set; }   // ex User
        public int AnswerNumber { get; set; }
        public int AnswerRating { get; set; }

        public Answer()
        {
            this.AnswerExamId = -1;
            this.AnswerQuestion = new Question();
            this.AnswerUserId = -1;
            this.AnswerNumber = -1;
            this.AnswerRating = -1;
        }
        public Answer( int examId, Question question ) {
            this.AnswerExamId = examId;
            this.AnswerQuestion = question;
            this.AnswerUserId = -1;
            this.AnswerNumber = -1;
            this.AnswerRating = -1;
        }
        public Answer( Question question ) {
            this.AnswerExamId = -1;
            this.AnswerQuestion = question;
            this.AnswerUserId = -1;
            this.AnswerNumber = -1;
            this.AnswerRating = -1;
        }
        public Answer(int examId, Question question, int userId, int answerNumber, int answerRating)
        {
            this.AnswerExamId = examId;
            this.AnswerQuestion = question;
            this.AnswerUserId = userId;
            this.AnswerNumber = answerNumber;
            this.AnswerRating = answerRating;
        }
        public Answer( Answer answer ) : this(answer.AnswerExamId, answer.AnswerQuestion, answer.AnswerUserId, answer.AnswerNumber, answer.AnswerRating) {}

        public virtual string ToMoreDetailedString() {
            StringBuilder sb = new StringBuilder( "Answer: " );
            sb.Append( "EXAMID: " + AnswerExamId.ToString() + "\n" );
            if ( AnswerQuestion != null )
                sb.Append( AnswerQuestion.ToString() );
            sb.Append( "STARD/END/RATING-DATE: " + AnswerUserId.ToString() + ", " );
            sb.Append( AnswerNumber.ToString() + ", " );
            sb.Append( AnswerRating.ToString() + '\n' );
            return sb.ToString();
        }
        public override string ToString() {
            return "unspezielle Antwort...";
        }
        
        public virtual int GetAchievedPoints( int maxPoints ) {
            return 0;
        }

        public virtual bool HasSetAnswer() {
            return false;
        }
        public virtual bool HasEmptyAnswer() {
            return !HasSetAnswer();
        }
        public virtual void SetDefaultAnswer() {
            ;
        }
    }
}
